package co.edu.usbcali.raju.games.chess;

import java.util.List;

import co.edu.usbcali.raju.games.chess.engine.ChessRuleEngine;
import co.edu.usbcali.raju.games.chess.helpers.ChessBoardFactory;
import co.edu.usbcali.raju.games.chess.model.ChessBoard;
import co.edu.usbcali.raju.model.IEvaluator;
import co.edu.usbcali.raju.model.Move;
import aima.core.search.adversarial.Game;

public class ChessGame implements Game<ChessBoard, Move, String> {
	
	public static final double MAX_UTILITY=10000;
	public static final double MIN_UTILITY=-10000;

	private String[] players=new String[]{"white","black"};
	private IEvaluator evaluator;

	@Override
	public List<Move> getActions(ChessBoard state) {
		List<Move> actions=ChessRuleEngine.getInstance().getMoves(state);
		return actions;
	}

	@Override
	public ChessBoard getInitialState() {
		return (ChessBoard)ChessBoardFactory.getInstance().getInitialBoard();
	}

	@Override
	public String getPlayer(ChessBoard state) {
		return state.getTurn();
	}

	@Override
	public String[] getPlayers() {
		return players;
	}

	@Override
	public ChessBoard getResult(ChessBoard state, Move action) {
		return (ChessBoard)ChessRuleEngine.getInstance().transition(state, action);
	}

	@Override
	public double getUtility(ChessBoard state, String player) {
		return state.getUtility(player,evaluator);
	}

	@Override
	public boolean isTerminal(ChessBoard state) {
		return ChessRuleEngine.getInstance().isTerminal(state);
	}

	public IEvaluator getEvaluator() {
		return evaluator;
	}

	public void setEvaluator(IEvaluator evaluator) {
		this.evaluator = evaluator;
	}
	
}
